﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BizAppFactory.Domain
{
    public partial class Attribute
    {
        public bool IsBasicDataType
        {
            get
            {
                return (this.BasicDataType != BasicDataTypes.Null);                
            }
        }

        public string EditorName
        {
            get
            {
                return this.Name + " : " + this.DataTypeName;
            }
        }

        public Role ToRole()
        {
            if (IsBasicDataType)
            {
                throw new ApplicationException("Attribute with basic data type can not be converted to role");
            }
            else
            {
                Role role = new Role() {
                Name = this.Name,
                DomainClass = this.DomainDataType,
                Multiplicity = (this.Required ? AssociationMultiplicityEnum.One: AssociationMultiplicityEnum.ZeroOrOne),
                PeerRoleMultiplicity = AssociationMultiplicityEnum.One};

                return role;
            }
        }
    }
}
